import $ from "jquery";

/**
 * 自定义指令
 */
export default {
  install(app: any) {
    // 风格样式
    app.directive("style", {
      mounted: (el: HTMLElement, binding: { value: string }) => {
        const { value } = binding;
        switch (value) {
          case "boxstyle_bg_1": {
            const lt = `<t class="boxstyle_bg_1_lt" />`;
            const t = `<t class="boxstyle_bg_1_t" />`;
            const lb = `<t class="boxstyle_bg_1_lb" />`;
            const rb = `<t class="boxstyle_bg_1_rb" />`;
            $(el).append(lt, t, lb, rb);
            $(el).addClass(value);
            break;
          }

          default: {
            $(el).addClass(value);
            break;
          }
        }
      },
    });
    // 提示
    app.directive("title", {
      created: (el: HTMLElement) => {
        const innerText = el.innerText;
        el.title = innerText;
      },
      updated: (el: HTMLElement) => {
        const innerText = el.innerText;
        el.title = innerText;
      },
    });
  },
};
